<template>
  <div>
    <el-form
      :model="form"
      status-icon
      :rules="rules"
      ref="form"
      label-width="100px"
      class="login-container"
    >
      <h3 class="login-title">登录</h3>
      <!-- 账户 -->
      <el-form-item
        label="用户名"
        label-width="80px"
        prop="username"
        class="username"
      >
        <el-input
          type="input"
          v-model="form.username"
          autocomplete="off"
          placeholder="请输入账号"
        >
        </el-input>
      </el-form-item>
      <!-- 密码 -->
      <el-form-item label="密码" label-width="80px" prop="password">
        <el-input
          type="input"
          v-model="form.password"
          autocomplete="off"
          placeholder="请输入密码"
        >
        </el-input>
      </el-form-item>
      <!-- 按牛 -->
      <el-form-item class="login_submit">
        <el-button type="primary" @click="login" class="login_submit">
          登录
        </el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { Mock } from "mockjs";
import { getMenu } from "../../api/data";
export default {
  data() {
    return {
      form: {},
      rules: {
        username: [
          {
            required: true,
            message: "请输入用户名",
            trigger: "blur",
          },
          {
            min: 3,
            message: "用户名长度===吊长",
            trigger: "blur",
          },
        ],
        password: [
          {
            required: true,
            message: "请输入密码",
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    login() {
      getMenu(this.form).then(({data:res}) => {
        if (res.code === 20000) {
            // 清除
          this.$store.commit("CLEARMENU");
             //   
          this.$store.commit("SETMENU", res.data.menu);
          this.$store.commit("SETTOKEN", res.data.menu);
          this.$store.commit("ADDMENU", this.$router);
          this.$router.push({
            name: "home",
          });
        } else {
          this.$message.warning(res.data.message);
        }
      });
      // const token = Mock.random.guid()
      // this.$store.commit('SETTOKEN',token)
      // this.$router.push({
      //     name:'home'
      // })
    },
  },
};
</script>

<style lang="less" scoped>
.login-container {
  border-radius: 15px;
  background-clip: padding-box;
  margin: 180px auto;
  width: 350px;
  padding: 35px 35px 15px 35px;
  background-color: #fff;
  border: 1px solid #eaeaea;
  box-shadow: 0 0 25px #cac6c6;
}
.login-title {
  margin: 0 auto 40px auto;
  text-align: center;
  color: #505458;
}
.login_submit {
  margin: 10px auto 0px auto;
}
</style>